package leetcode;

public class CountNumbers {

	public static void main(String[] args) {
		CountNumbers numbers = new CountNumbers();
		System.out.println(numbers.countNumbersWithUniqueDigits(3));

	}

	public int countNumbersWithUniqueDigits(int n) {
		if (n < 0) {
			return 0;
		}
		if (n == 0) {
			return 1;
		}
		if (n == 1) {
			return 10;
		}
		// 由于10位数字之后，再多也和10相同了，所以就令n = 10 (n >= 10)
		if (n >= 10) {
			n = 10;
		}
		int[] number = new int[n + 1];
		number[1] = 10;
		int cur = 9;
		for (int i = 2; i < number.length; i++) {
			cur = 9;
			for (int k = 2; k <= i; k++) {
				cur *= (11 - k);
			}
			number[i] = cur + number[i - 1];
		}
		for (int i : number) {
			System.out.print(" " + i);
		}
		return number[n];
	}
	
}
